﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Microsoft.Xna.Framework.Content;

namespace Tomahawk.Resources.Particles
{
    public class ParticleSettingsCollectionReader : ContentTypeReader<ParticleSettingsCollection>
    {
        #region Properties
        public delegate bool InitParticleSettingsCollectionDelegate(ParticleSettingsCollection collection);
        public static event InitParticleSettingsCollectionDelegate OnInitParticleSettingsCollection;
        #endregion

        protected override ParticleSettingsCollection Read(ContentReader input, ParticleSettingsCollection existingInstance)
        {
            ParticleSettingsCollection output = null;

            XmlSerializer x = new XmlSerializer(typeof(ParticleSettingsCollection));
            output = (ParticleSettingsCollection)x.Deserialize(input.BaseStream);

            foreach (ParticleSettings settings in output.collection)
            {
                output.ParticleSettings.Add(settings.name, settings);
            }

            output.collection.Clear();
            
            if (OnInitParticleSettingsCollection != null)
            {
                OnInitParticleSettingsCollection(output);
            }
            
            return output;
        }
    }
}
